﻿#面向对象高级编程

class Student(object):
	pass;

s = Student();
#给这个类绑定属性
s.name = 'jing';
print(s.name);

#给类绑定一个方法 
def set_age(self,age):
	self.age = age;

from types import MethodType;
s.set_age = MethodType(set_age,s);
s.set_age(25);
print(s.age);
#注意这里绑定的类和属性只是当前实例的有用

#给所有实例都绑定方法 便是对类绑定方法
def set_score(self,score):
	self.score = score;
Student.set_score = MethodType(set_score,Student);
s.set_score(100);
print(s.score);
#__slots__对类添加的属性进行限定 __slots__ = ('name','age')

######################使用property设置函数的getset方法#########################
class Teather(object):
	#get方法
	@property
	def birth(self):
		print("调用的get方法")
		return self.__birth;
	
	#set方法
	@birth.setter
	def birth(self,value):
		if not isinstance(value,int):
			raise ValueError("score must be ane int");
		self.__birth = value;
		
T = Teather();
T.birth = 90;
print(T.birth);
# T.birth = "qw"
print(T.birth);
###########类似与接口的 竟然叫做多重继承##########
class Animal(object):
	pass;

class Flyable(object):
	def fly(self):
		print("fly");
		
class Dog(Animal,Flyable):
	pass;
	
D = Dog();
D.fly();

############枚举###############
from enum import Enum
Month = Enum("Month",("jan","feb","mar"));
print(Month.jan,":",Month.jan.value);
for name,member in Month.__members__.items():
	print(name,":",member)

#自定义枚举数字
from enum import Enum,unique;

class Weekday(Enum):
	Sun = 0
	Mon = 1
	Tue = 4
print(Weekday.Tue.value);
